﻿#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QGraphicsScene>
#include <QDebug>
#include <QMessageBox>
#include <QFileDialog>
#include <QTime>
#include "writelog.h"
#include <QThreadPool>
#include "message.h"

#define QDEBUG debugMessage::instance()->sendMessage
bool camConStatus[CAMERA_NUMBER] = {false, false, false, false}; //相机连接状态 0为未连接，1为连接
bool m_coilsValue[13] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; //临时保存每个线圈值
bool isProcess[CAMERA_NUMBER] ={false, false, false, false};

MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{
    ui->setupUi(this);
    this->setWindowState(Qt::WindowMaximized);//设置窗口最大化
    //    this->setWindowState(Qt::WindowFullScreen);//设置窗口最大化
    //    this->setWindowFlags(Qt::FramelessWindowHint);//去掉标题栏
    //    this->setGeometry(QRect(100, 100, 1366, 724));//可设置窗口显示的方位与大小

    ui->btnCam->setEnabled(false);
    ui->btnObj->setEnabled(false);
    ui->btnRun->setEnabled(false);

    //*************主窗口显示图片****************//
    connect(debugMessage::instance(), &debugMessage::sendMessage, this, &MainWindow::messageshow, Qt::QueuedConnection);
    connect(CoilsStatus::instance(), &CoilsStatus::coilsSendStart, this, &MainWindow::doProCoilsSendStart, Qt::QueuedConnection);

    //*************主窗口显示图片****************//
    m_winId[0] = (Hlong)ui->graphicsView->winId();
    m_winId[1] = (Hlong)ui->graphicsView2->winId();
    m_winId[2] = (Hlong)ui->graphicsView3->winId();
    m_winId[3] = (Hlong)ui->graphicsView4->winId();

    ui->btnLoad->setIcon(QIcon("./resource/load.png"));
    ui->btnCam->setIcon(QIcon("./resource/cam.png"));
    ui->btnConnect->setIcon(QIcon("./resource/client.png"));
    ui->btnObj->setIcon(QIcon("./resource/study1.png"));
    ui->btnProduct->setIcon(QIcon("./resource/product.png"));
    ui->btnRun->setIcon(QIcon("./resource/run.png"));
    ui->btnClear->setIcon(QIcon("./resource/clear.png"));

    //**********状态栏显示时间***********//
    m_showTime = startTimer(1000);

    //*************相机显示界面初始化**********//
    camset = new camSetting();
    objset = new objSetting();

    //**********数据保存初始化***********//
    data = new datasaveread1();
    data->setAttribute(Qt::WA_ShowModal, true);//属性设置
    data->setWindowModality(Qt::ApplicationModal);//设置阻塞类型
    connect(data, SIGNAL(sendDataPara(QString)),
            this, SLOT(doProDataSendPara(QString))); //连接data发送数据与主窗口

    //**********目标检测初始化***********//
    obj0 = new objlocation0(0);
    obj0->setObjectName("obj0");
    obj0->setWindowTitle(QStringLiteral("检测0"));
    objset->setShowWidget(obj0, 0);
    connect(obj0, SIGNAL(sendCamSaveSignal(int)), this, SLOT(doProCamSaveData(int)));        //连接obj发送参数数据与主窗口
    connect(obj0, SIGNAL(sendMakeModelResult(bool)), this, SLOT(doProObjMakeModelResult(bool)));       //连接obj
    connect(obj0, SIGNAL(sendDataSaveResult(bool)), this, SLOT(doProDataSaveResult(bool)));

    obj1 = new objlocation1(1);
    obj1->setObjectName("obj1");
    obj1->setWindowTitle(QStringLiteral("检测1"));
    objset->setShowWidget(obj1, 1);
    connect(obj1, SIGNAL(sendCamSaveSignal(int)), this, SLOT(doProCamSaveData(int)));        //连接obj发送参数数据与主窗口
    connect(obj1, SIGNAL(sendMakeModelResult(bool)), this, SLOT(doProObjMakeModelResult(bool)));
    connect(obj1, SIGNAL(sendDataSaveResult(bool)), this, SLOT(doProDataSaveResult(bool)));

    obj2 = new objlocation2(2);
    obj2->setObjectName("obj2");
    obj2->setWindowTitle(QStringLiteral("检测2"));
    objset->setShowWidget(obj2, 2);
    connect(obj2, SIGNAL(sendCamSaveSignal(int)), this, SLOT(doProCamSaveData(int)));        //连接obj发送参数数据与主窗口
    connect(obj2, SIGNAL(sendMakeModelResult(bool)), this, SLOT(doProObjMakeModelResult(bool)));
    connect(obj2, SIGNAL(sendDataSaveResult(bool)), this, SLOT(doProDataSaveResult(bool)));

    obj3 = new objlocation3(3);
    obj3->setObjectName("obj3");
    objset->setShowWidget(obj3, 3);
    obj3->setWindowTitle(QStringLiteral("检测3"));
    connect(obj3, SIGNAL(sendCamSaveSignal(int)), this, SLOT(doProCamSaveData(int)));        //连接obj发送参数数据与主窗口
    connect(obj3, SIGNAL(sendMakeModelResult(bool)), this, SLOT(doProObjMakeModelResult(bool)));
    connect(obj3, SIGNAL(sendDataSaveResult(bool)), this, SLOT(doProDataSaveResult(bool)));

    //*************相机初始化**********//
    for (int i = 0; i < CAMERA_NUMBER; i++)
    {
        cam[i] = new balserForm1("camera" + QString::number(i));
        cam[i]->setObjectName("cam" + QString::number(i));
        cam[i]->setWindowTitle(QStringLiteral("相机") + QString::number(i));
        camset->setShowWidget(cam[i], i);
        camConStatus[i] = cam[i]->connectCam();
        if (camConStatus[i] == true)
        {
            connect(cam[i], SIGNAL(camGrabOneResult(Hobject)), this, SLOT(doProCamResult(Hobject)));
            QDEBUG(QStringLiteral("相机") + QString::number(i) + QStringLiteral("连接成功！"));
        }
        if (camConStatus[i] == false)
        {
            QDEBUG(QStringLiteral("相机") + QString::number(i) + QStringLiteral("连接失败！"));
        }
    }

    //**********通讯初始化***********//
    mod = new Widget();
    //    modbus->setAttribute(Qt::WA_ShowModal, true);//属性设置
    //    modbus->setWindowModality(Qt::ApplicationModal);//设置阻塞类型
    bool status = mod->isConnect();
    if (status == false)
    {
        QDEBUG( QStringLiteral("Modbus打开端口失败，请先开启主站！"));
    }
    if (status == true)
    {
        QDEBUG( QStringLiteral("Modbus打开端口成功！"));
    }

    //***********登陆初始化***********//
    load = new loadDialog();
    load->setAttribute(Qt::WA_ShowModal, true);//属性设置
    load->setWindowModality(Qt::ApplicationModal);//设置阻塞类型
    connect(load, SIGNAL(sendLoadStatus(bool)), this, SLOT(doProLoadStatus(bool))); //连接obj发送模板制作成功信号与主窗口

    //**********多线程参数初始化***************
    load->on_btnOk_clicked(); //直接登录
    data->on_btnOK_clicked(); //直接载入当前产品
}

MainWindow::~MainWindow()
{
    delete ui;
}

void MainWindow::doProCamSaveData(int schedule)
{
    QString objName = sender()->objectName();
    //    qDebug()<<"objName"<<objName;
    for (int i = 0; i < CAMERA_NUMBER; i++)
    {
        if (objName == "obj" + QString::number(i))
        {
            //            qDebug()<<"shaomian"<<"obj"+QString::number(i);
            cam[i]->saveData(i, schedule);
        }
    }
}

void MainWindow::doProObjMakeModelResult(bool)
{
    QString objName = sender()->objectName();
    for (int i = 0; i < CAMERA_NUMBER; i++)
    {
        if (objName == "obj" + QString::number(i))
        {
            QDEBUG( QStringLiteral("检测")
                    + QString::number(i) + QStringLiteral("模板制作成功！"));
        }
    }
}

void MainWindow::doProDataSaveResult(bool ret)
{
    QString objName = sender()->objectName();
    for (int i = 0; i < CAMERA_NUMBER; i++)
    {
        if (objName == "obj" + QString::number(i))
        {
            if (ret)
            {
                QDEBUG( QStringLiteral("检测")
                        + QString::number(i) + QStringLiteral("数据保存成功！"));
                return;
            }
            QDEBUG( QStringLiteral("检测")
                    + QString::number(i) + QStringLiteral("数据保存失败！"));
        }
    }
}

void MainWindow::doProDataSendPara(QString currentProjectName)
{
    QDEBUG(u8"打开工程成功！");
    m_curProjectName = currentProjectName; //获取当前工程名
    for (int i = 0; i < CAMERA_NUMBER; i++)
    {
        cam[i]->setProjectName(i, m_curProjectName);
        if (m_WindowHandle[i].Num() == 0)
        {
            open_window(0, 0, (Hlong)ui->groupBox_2->width(), (Hlong)ui->groupBox_2->height(), m_winId[i], "", "", &m_WindowHandle[i]);
        }
    }

    obj0->setProjectName(m_curProjectName);
    obj0->setWinHandle(m_WindowHandle[0]);
    obj0->setInitialize();

    obj1->setProjectName(m_curProjectName);
    obj1->setWinHandle(m_WindowHandle[1]);
    obj1->setInitialize();

    obj2->setProjectName(m_curProjectName);
    obj2->setWinHandle(m_WindowHandle[2]);
    obj2->setInitialize();

    obj3->setProjectName(m_curProjectName);
    obj3->setWinHandle(m_WindowHandle[3]);
    obj3->setInitialize();

    //************显示按钮使能*********//
    if (m_isloaded == true) //已登陆，则设置按钮可用
    {
        ui->btnCam->setEnabled(true);
    }
    ui->btnRun->setEnabled(true);

}
void MainWindow::timerEvent(QTimerEvent *event)
{
    if (event->timerId() == m_showTime)
    {
        //*********显示系统时间************
        QDateTime current_time = QDateTime::currentDateTime();
        QString timestr = current_time.toString( QStringLiteral("yyyy年MM月dd日 hh:mm:ss") + "  "); //设置显示的格式
        QFont font;
        font.setFamily("宋体");
        font.setPixelSize(20);
        font.setBold(true);
        ui->label_2->setAlignment(Qt::AlignRight | Qt::AlignVCenter);
        ui->label_2->setFont(font);
        ui->label_2->setText(timestr);

        //*********显示NG个数************
        m_ngNumber = m_totalNumber - m_okNumber; //显示NG个数
        if (m_totalNumber != 0)
        {
            double ng_scacle = (double)m_ngNumber / m_totalNumber;
            QString str = " (" + QString::number(100 * ng_scacle, 'f', 2) + "%)";
            ui->label_ng->setText(QString::number(m_ngNumber) + str); //显示总个数
        }
        event->accept();
    }

    if (event->timerId() == m_getCoilsValue)
    {
        QVector<quint16> values;
        mod->readRequest(0, 100, 4, &values);
        if (values.at(0) == 1 )
        {
            QThread::msleep(100);
            QDEBUG( u8"读到100线圈值为1，开始处理");
            if( values.at(0)==1)
            {
                r0 = new threadObj0(cam[0], obj0);
                QThreadPool::globalInstance()->start(r0);
            }
            if( values.at(1)==1)
            {
                r1 = new threadObj1(cam[1], obj1);
                QThreadPool::globalInstance()->start(r1);
            }
            if( values.at(2)==1)
            {
                r2 = new threadObj2(cam[2], obj2);
                QThreadPool::globalInstance()->start(r2);
            }
            if( values.at(3)==1)
            {
                r3 = new threadObj3(cam[3], obj3);
                QThreadPool::globalInstance()->start(r3);
            }
            m_coilsValue[0]=values.at(0);
            m_coilsValue[1]=values.at(1);
            m_coilsValue[2]=values.at(2);
            m_coilsValue[3]=values.at(3);
            QThread::msleep(2000);
//            loop.exec(); //线程堵塞，直到发送完数据后，才继续
            //            sendCoilsValue();
        }
//        QDEBUG( QStringLiteral("xxxxxxxxxxxxxx"));
        event->accept();
    }
}

void MainWindow::closeEvent(QCloseEvent *event)
{
    int isOk = QMessageBox::warning(NULL, QStringLiteral("提醒"), QStringLiteral("确定退出吗？"),
                                    QMessageBox::Ok, QMessageBox::Cancel);
    if (isOk == QMessageBox::Ok)
    {
        camset->close();
        objset->close();
        mod->close();
        event->accept();
    }
    else
        event->ignore();
}

void MainWindow::sendCoilsValue()
{
    QVector<quint16> m_data;
    for (int i = 4; i < 13; i++)
    {
        if (m_coilsValue[i] != 0 && m_coilsValue[0] == 0 && m_coilsValue[1] == 0 && m_coilsValue[2] == 0 && m_coilsValue[3] == 0)
        {
            for (int i = 0; i < 13; i++)
            {
                //                ui->plainTextEditInformation->insertPlainText(" " + QString::number(m_coilsValue[i]));
                m_data.push_back(m_coilsValue[i]);
                m_coilsValue[i] = 0;
            }
            //****************显示ok个数*******************//
            m_totalNumber++;  //显示总个数
            ui->label_total->setText(QString::number(m_totalNumber));  //显示总个数
            if (m_data.at(7) == 1 && m_data.at(8) == 1)
            {
                m_okNumber+=1;  //显示OK个数
                if (m_totalNumber != 0)
                {
                    double ok_scacle = (double)m_okNumber / m_totalNumber;
                    QString str = " (" + QString::number(100 * ok_scacle, 'f', 2) + "%)";
                    ui->label_ok->setText(QString::number(m_okNumber) + str); //显示总个数
                }
            }
            //*****************************
            if (m_data.size() == 13)
            {
                mod->writeRequest(0, 100, m_data);
                QDEBUG( QStringLiteral("13个线圈值发送成功！"));
                m_data.clear();
            }
            else
                QDEBUG( QStringLiteral("13个线圈值不全，发送失败！"));
            return;
        }
    }
}

QString MainWindow::showCurTime()
{
    QDateTime current_time = QDateTime::currentDateTime();
    QString timestr = current_time.toString( QStringLiteral("hh:mm:ss.zzz")); //设置显示的格式
    return QStringLiteral("【") + timestr + QStringLiteral("】");
}

void MainWindow::doProCamResult(Hobject image1)
{
    HTuple width, height;
    QString objName = sender()->objectName();
    ui->btnObj->setEnabled(true);
    ui->btnRun->setEnabled(true);

    get_image_size(image1, &width, &height);
    //*************相机0*************
    if (objName == "cam0")
    {
        set_part(m_WindowHandle[0], 0, 0, height - 1, width - 1);
        disp_obj(image1, m_WindowHandle[0]);
        obj0->setTempImage(image1);
    }

    //*************相机1*************
    else if (objName == "cam1")
    {
        set_part(m_WindowHandle[1], 0, 0, height - 1, width - 1);
        disp_obj(image1, m_WindowHandle[1]);
        obj1->setTempImage(image1);
    }

    //*************相机2*************
    else if (objName == "cam2")
    {
        set_part(m_WindowHandle[2], 0, 0, height - 1, width - 1);
        disp_obj(image1, m_WindowHandle[2]);
        obj2->setTempImage(image1);
    }
    //*************相机3*************
    else if (objName == "cam3")
    {
        set_part(m_WindowHandle[3], 0, 0, height - 1, width - 1);
        disp_obj(image1, m_WindowHandle[3]);
        obj3->setTempImage(image1);
    }
}

void MainWindow::doProLoadStatus(bool status)
{
    m_isloaded = status;
    if (m_isloaded == true) //已登陆，则设置按钮可用
    {
        data->setUiEnable(true);
        ui->btnCam->setEnabled(true);
        ui->btnObj->setEnabled(true);
        QDEBUG(QStringLiteral("管理员登陆成功！"));
    }
    if (m_isloaded == false)
    {
        data->setUiEnable(false);
        ui->btnCam->setEnabled(false);
        ui->btnObj->setEnabled(false);
    }
}

void MainWindow::messageshow(const QString &msg)
{
    ui->plainTextEditInformation->appendPlainText(showCurTime() +msg);
}

void MainWindow::doProCoilsSendStart(int address)
{
    QDEBUG(u8"开始处理线圈"+QString::number(address));
    sendCoilsValue();
    //    loop.quit();
}

void MainWindow::on_btnLoad_clicked()
{
    load->show();
}

void MainWindow::on_btnProduct_clicked()
{
    data->show();
}

void MainWindow::on_btnConnect_clicked()
{
    mod->show();
}

void MainWindow::on_btnRun_clicked()
{
    if (isRun == false)
    {
        QDEBUG( QStringLiteral("***连续运行开始***"));

        ui->btnProduct->setEnabled(false);
        ui->btnLoad->setEnabled(false);
        ui->btnCam->setEnabled(false);
        ui->btnConnect->setEnabled(false);
        ui->btnObj->setEnabled(false);

        isRun = true;
        ui->btnRun->setIcon(QIcon("./resource/stop.png"));
        m_getCoilsValue = startTimer(1000);
        return;
    }
    if (isRun == true)
    {
        ui->btnProduct->setEnabled(true);
        ui->btnLoad->setEnabled(true);
        ui->btnConnect->setEnabled(true);

        if (m_isloaded == true) //已登陆，则设置按钮可用
        {
            ui->btnCam->setEnabled(true);
            ui->btnObj->setEnabled(true);
        }
        isRun = false;
        ui->btnRun->setIcon(QIcon("./resource/run.png"));
        killTimer(m_getCoilsValue);
        QDEBUG(QStringLiteral("***连续运行结束***"));
        return;
    }
}

void MainWindow::on_btnClear_clicked()
{
    ui->plainTextEditInformation->clear();
}

void MainWindow::on_btnReset_clicked()
{
    m_ngNumber = 0;
    m_totalNumber = 0;
    m_okNumber = 0;
    ui->label_total->setText("0");
    ui->label_ng->setText("0 (0%)");
    ui->label_ok->setText("0 (0%)");
}

void MainWindow::on_btnCam_clicked()
{
    camset->show();
}

void MainWindow::on_btnObj_clicked()
{
    objset->show();
}

threadObj0::threadObj0()
{
}

threadObj0::threadObj0(balserForm1 *cam, objlocation0 *obj)
{
    this->setAutoDelete(true);
    cam0 = cam;
    obj0 = obj;
}

void threadObj0::run()
{
    if (true)          //相机0检测开始
    {
        Hobject abc;
        if (camConStatus[0] == false) //相机未连接
        {
            qDebug()<<"1111111111111111xiangjiqidong";
            QDEBUG(u8"相机0未连接，请连接相机！");
            m_coilsValue[0] = 0;
//            m_coilsValue[5] = 1;   //................
            CoilsStatus::instance()->coilsSendStart(100);
            QThread::msleep(500);
            return;
        }
        cam0->setCamPara(1);
        cam0->grabOneFrame(&abc);
        bool ret = obj0->process(abc);  //处理并获得参数结果
        if (ret == true)
        {
            m_coilsValue[5] = 1;
            m_coilsValue[9] = 0;
            QDEBUG(u8"相机0找到目标，检测成功！");
        }
        else
        {
            m_coilsValue[5] = 0;
            m_coilsValue[9] = 1;
            QDEBUG(u8"相机0未找到目标，检测失败！");
        }
        m_coilsValue[0] = 0;
        emit CoilsStatus::instance()->coilsSendStart(100);
        QThread::msleep(500);
    }
}

threadObj1::threadObj1()
{
}

threadObj1::threadObj1(balserForm1 *cam, objlocation1 *obj)
{
    this->setAutoDelete(true);
    cam1 = cam;
    obj1 = obj;
}

void threadObj1::run()
{
    if (true)          //相机1检测开始
    {
        if (camConStatus[1] == false) //相机未连接
        {
            QDEBUG(u8"相机1未连接，请连接相机！");
            qDebug()<<"1111111111111111xiangjiqidong";
            //            m_coilsValue[6] = 1; //.....................
            m_coilsValue[1] = 0;
            CoilsStatus::instance()->coilsSendStart(101);
            QThread::msleep(500);
            return;
        }
        Hobject abc;
        cam1->setCamPara(1);
        cam1->grabOneFrame(&abc);
        bool ret = obj1->process(abc); //处理并获得参数结果
        if (ret == true)
        {
            m_coilsValue[6] = 1;
            m_coilsValue[10] = 0;
            QDEBUG(u8"相机1找到目标，检测成功！");
        }
        else
        {
            m_coilsValue[6] = 0;
            m_coilsValue[10] = 1;
            QDEBUG(u8"相机1未找到目标，检测失败！");
        }
        m_coilsValue[1] = 0;
        CoilsStatus::instance()->coilsSendStart(101);
        QThread::msleep(500);
    }
}

threadObj2::threadObj2()
{
}

threadObj2::threadObj2(balserForm1 *cam, objlocation2 *obj)
{
    this->setAutoDelete(true);
    cam2 = cam;
    obj2 = obj;
}

void threadObj2::run()
{
    if (true)          //相机0检测开始
    {
        if (camConStatus[2] == false) //相机未连接
        {
            QDEBUG(u8"相机2未连接，请连接相机！");
            m_coilsValue[2] = 0;
            //            m_coilsValue[7] = 1; //.....................
            QThread::msleep(200);
            return;
        }
        Hobject abc;
        cam2->setCamPara(1);
        cam2->grabOneFrame(&abc);
        bool ret = obj2->process(abc); //处理并获得参数结果
        if (ret == true)
        {
            m_coilsValue[7] = 1;
            m_coilsValue[11] = 0;
            QDEBUG(u8"相机2找到目标，检测成功！");
        }
        else
        {
            m_coilsValue[11] = 1;
            m_coilsValue[7] = 0;
            QDEBUG(u8"相机2未找到目标，检测失败！");
        }
        m_coilsValue[2] = 0;
        CoilsStatus::instance()->coilsSendStart(102);
        QThread::msleep(500);
    }
}

threadObj3::threadObj3()
{
}

threadObj3::threadObj3(balserForm1 *cam, objlocation3 *obj)
{
    this->setAutoDelete(true);
    cam3 = cam;
    obj3 = obj;
}

void threadObj3::run()
{
    if (true)          //相机3检测开始
    {
        if (camConStatus[3] == false) //相机未连接
        {
            qDebug()<<"33333333333333333xiangjiqidong";
            QDEBUG(u8"相机3未连接，请连接相机！");
            m_coilsValue[3] = 0;
            //            m_coilsValue[8] = 1; //,,,,,,,,,,,,,,,,,,,,,,,,
            CoilsStatus::instance()->coilsSendStart(103);
            QThread::msleep(200);
            return;
        }
        Hobject abc;
        cam3->setCamPara(1);
        cam3->grabOneFrame(&abc);
        bool ret = obj3->process(abc); //处理并获得参数结果
        if (ret == true)
        {
            m_coilsValue[8] = 1;
            m_coilsValue[12] = 0;
            QDEBUG(u8"相机3找到目标，检测成功！");
        }
        else
        {
            m_coilsValue[12] = 1;
            m_coilsValue[8] = 0;
            QDEBUG(u8"相机3未找到目标，检测失败！");
        }
        m_coilsValue[3] = 0;
        CoilsStatus::instance()->coilsSendStart(103);
        QThread::msleep(500);
    }
}

threadSendValue::threadSendValue()
{

}

threadSendValue::threadSendValue(Widget *mod)
{
    this->setAutoDelete(true);
    m_mod = mod;
}

void threadSendValue::run()
{
    for (int i = 0; i < 13; i++)
    {
        qDebug()<<"fasonghjieguo "<<i<<" "<<m_coilsValue[i];
        QThread::msleep(200);
    }

    QVector<quint16> m_data;
    for (int i = 4; i < 13; i++)
    {
        if (m_coilsValue[i] != 0 && m_coilsValue[0] == 0 && m_coilsValue[1] == 0 && m_coilsValue[2] == 0 && m_coilsValue[3] == 0)
        {
            qDebug()<<"fasonghjieguo";
            //            m_totalNumber++;  //显示总个数
            //            ui->label_total->setText(QString::number(m_totalNumber));  //显示总个数
            for (int i = 0; i < 13; i++)
            {
                //                ui->plainTextEditInformation->insertPlainText(" " + QString::number(m_coilsValue[i]));
                //                if (m_coilsValue[7] == 1 && m_coilsValue[8] == 1)
                //                {
                //                    m_okNumber++;  //显示OK个数
                //                    if (m_totalNumber != 0)
                //                    {
                //                        double ok_scacle = m_okNumber / m_totalNumber;
                //                        QString str = " (" + QString::number(100 * ok_scacle, 'f', 1) + "%)";
                //                        ui->label_ok->setText(QString::number(m_okNumber) + str); //显示总个数
                //                    }
                //                }
                m_data.push_back(m_coilsValue[i]);
                m_coilsValue[i] = 0;
            }
            if (m_data.size() == 13)
            {
                m_mod->writeRequest(1, 100, m_data);
                qDebug()<<QStringLiteral("13个线圈值发送成功！");
                QDEBUG(u8"13个线圈值发送成功！");
                m_data.clear();
            }
            else
                qDebug()<<QStringLiteral("13个线圈值不全，发送失败！");
            QDEBUG(u8"13个线圈值不全，发送失败！");
            break;
        }
    }
}
